﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


using DeviceManagementIT.DevicesManager.DevicesManagement;
using DeviceManagementIT.RoomDevices;
using DeviceManagementIT.RoomDevices.ManagerRoom;
using DeviceManagementIT.HandingDevices;
using DeviceManagementIT.HandingDevices.MangagerHandingDevices;
using DeviceManagementIT.Formain;
using DeviceManagementIT.Formain.AccountManager;
using DeviceManagementIT.DevicesManager.Unit;
using DeviceManagementIT.StatisticalReports.ListOfVouchers;


namespace Presentation
{
    public partial class DeviceManagement : RibbonForm
    {
        frmDevicesNone d_frmDevicesNone = new frmDevicesNone();
        frmRoomDevicesNone d_frmRoomDevicesNone = new frmRoomDevicesNone();
        frmHandingDevicesNone d_frmHandingDevicesNone = new frmHandingDevicesNone();
        frmFormainNone d_frmFormainNone = new frmFormainNone();
        public DeviceManagement()
        {
            InitializeComponent();
            InitSkinGallery();
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkin, true);
        }
        void TabCreating(DevExpress.XtraTab.XtraTabControl tabControl, string Text, string Name,
            DevExpress.XtraEditors.XtraForm form, int imageIndex)
        {
            int index = KiemTraTonTai(tabControl, Name);
            if (index >= 0)
            {
                tabControl.SelectedTabPage = tabControl.TabPages[index];
                tabControl.SelectedTabPage.Text = Text;
            }
            else
            {
                DevExpress.XtraTab.XtraTabPage tabpage = new DevExpress.XtraTab.XtraTabPage { Text = Text, Name = Name, ImageIndex = imageIndex };
                tabControl.TabPages.Add(tabpage);
                tabControl.SelectedTabPage = tabpage;
                form.TopLevel = false;
                form.Parent = tabpage;
                form.Show();
                form.Dock = DockStyle.Fill;
            }
        }

        static int KiemTraTonTai(DevExpress.XtraTab.XtraTabControl tabControlName, string tabName)
        {
            int re = -1;
            for (int i = 0; i < tabControlName.TabPages.Count; i++)
            {
                if (tabControlName.TabPages[i].Name == tabName)
                {
                    re = i;
                    break;
                }
            }
            return re;
        }

        private void bbtnDsThietBi_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmListQuipment m_frmListQuipment = new frmListQuipment();
            this.TabCreating(xtraTabControl_Main, "Quản lý thiết bị", "quanlythietbi", d_frmDevicesNone, 0);
            //{ manv = MaNV, Quyen = nvright };
            TabCreating(d_frmDevicesNone.xtraTabControl, "Danh sách thiết bị", "dsthietbi", m_frmListQuipment, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
            //FrmKhachHang_FromChinh.xtraTabControl_KhachHang.SelectedTabPage.Image = imageCollection_16x16.Images[3];
        }

        private void bBtnThemTB_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmAddDevices m_frmAddDevices = new frmAddDevices();
            this.TabCreating(xtraTabControl_Main, "Quản lý thiết bị", "quanlythietbi", d_frmDevicesNone, 0);
            TabCreating(d_frmDevicesNone.xtraTabControl, "Thêm thiết bị", "themthietbi", m_frmAddDevices, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bBtnCapNhatTB_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmEditQuiqment m_frmEditQuiqment = new frmEditQuiqment();
            this.TabCreating(xtraTabControl_Main, "Quản lý thiết bị", "quanlythietbi", d_frmDevicesNone, 0);
            TabCreating(d_frmDevicesNone.xtraTabControl, "Cập nhật thiết bị", "capnhatthietbi", m_frmEditQuiqment, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnDsDonViTinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmListUnit m_frmEditQuiqment = new frmListUnit();
            this.TabCreating(xtraTabControl_Main, "Quản lý thiết bị", "quanlythietbi", d_frmDevicesNone, 0);
            TabCreating(d_frmDevicesNone.xtraTabControl, "Danh Sách Đơn vị tính", "dsdonvitinh", m_frmEditQuiqment, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnThemDonViTinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmAddUnit m_frmAddUnit = new frmAddUnit();
            m_frmAddUnit.Show();
        }


        private void bbtnHieuChinhDVT_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmEditUnit m_frmEditUnit = new frmEditUnit();
            m_frmEditUnit.Show();
        }

        private void bbtnDsPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmRoomDevices m_frmRoomDevices = new frmRoomDevices();
            this.TabCreating(xtraTabControl_Main, "Quản lý phòng", "quanlyphong", d_frmRoomDevicesNone, 0);
            TabCreating(d_frmRoomDevicesNone.xtraTabControl, "Danh sách phòng", "dsphong", m_frmRoomDevices, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnCapNhatPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmEditRoom m_frmEditRoom = new frmEditRoom();
            this.TabCreating(xtraTabControl_Main, "Quản lý phòng", "quanlyphong", d_frmRoomDevicesNone, 0);
            TabCreating(d_frmRoomDevicesNone.xtraTabControl, "Danh sách phòng", "dsphong", m_frmEditRoom, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnThemPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmAddRoom m_frmAddRoom = new frmAddRoom();
            m_frmAddRoom.Show();
        }

        private void bbtnDsBanGiao_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmListHandingDevices m_frmListHandingDevices = new frmListHandingDevices();
            this.TabCreating(xtraTabControl_Main, "Quản lý bàn giao", "quanlybangiao", d_frmRoomDevicesNone, 0);
            TabCreating(d_frmRoomDevicesNone.xtraTabControl, "Danh sách bàn giao", "dsbangiao", m_frmListHandingDevices, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnBanGiaoTB_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmAddHandingDevices m_frmAddHandingDevices = new frmAddHandingDevices();
            this.TabCreating(xtraTabControl_Main, "Quản lý bàn giao", "quanlybangiao", d_frmRoomDevicesNone, 0);
            TabCreating(d_frmRoomDevicesNone.xtraTabControl, "Thêm bàn giao", "thembangiao", m_frmAddHandingDevices, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnNguoidung_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmAddHandingDevices m_frmAddHandingDevices = new frmAddHandingDevices();
            this.TabCreating(xtraTabControl_Main, "Trang chính", "trangchinh", d_frmFormainNone, 0);
            TabCreating(d_frmFormainNone.xtraTabControl, "Thông tin tài khoản", "thongtintaikhoan", m_frmAddHandingDevices, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnDsTaiKhoan_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmAccountList m_frmAddHandingDevices = new frmAccountList();
            this.TabCreating(xtraTabControl_Main, "Trang chính", "trangchinh", d_frmFormainNone, 0);
            TabCreating(d_frmFormainNone.xtraTabControl, "Danh sách tài khoản", "thongtintaikhoan", m_frmAddHandingDevices, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

        private void bbtnTtTaiKhoan_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmInfoAccount m_frmInfoAccount = new frmInfoAccount();
            m_frmInfoAccount.Show();
        }

        private void btnKiemke_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmInventory m_frmEditQuiqment = new frmInventory();
            this.TabCreating(xtraTabControl_Main, "Quản lý thiết bị", "quanlythietbi", d_frmDevicesNone, 0);
            TabCreating(d_frmDevicesNone.xtraTabControl, "Danh Sách Đơn vị tính", "dsdonvitinh", m_frmEditQuiqment, -1);
            d_frmDevicesNone.Dock = DockStyle.Fill;
        }

    }
}